package com.lidy.tankbattle.tankutils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lidy.tankbattle.tankgame2.constant.WallPriorities;
import com.lidy.tankbattle.tankgame2.wall.Wall;
import redis.clients.jedis.Jedis;

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author lidy
 * @version V1.0
 * @classname TestUtils
 * @description 测试工具类
 * @date 2022/6/3 11:02
 */
public class TestUtils {


    public static void main(String[] args) {
        redisTest();
    }

    /**
     * @author: lidy
     * @description: 随机数测试
     * @date: 2022/6/3 11:03
     */
    public static void randomTest() {
        int[] arr = new int[5];
        Random random = new Random(1);
        for (int i = 0; i < 10000; i++) {
            int r = random.nextInt(5);
            // System.out.println(r);
            switch (r) {
                case 0 -> arr[0]++;
                case 1 -> arr[1]++;
                case 2 -> arr[2]++;
                case 3 -> arr[3]++;
                default -> arr[4]++;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.println(i + "-" + arr[i]);
        }
    }

    public static void mathRandomTest() {
        int[] arr = new int[5];
        for (int i = 0; i < 10000; i++) {
            int r = ((int)(Math.random() * 100)) % 5;
            // System.out.println(r);
            switch (r) {
                case 0 -> arr[0]++;
                case 1 -> arr[1]++;
                case 2 -> arr[2]++;
                case 3 -> arr[3]++;
                default -> arr[4]++;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.println(i + "-" + arr[i]);
        }
    }

    public static void redisTest() {

        try (Jedis jedis = new Jedis("124.223.101.21", 6379)) {
            String ping = jedis.ping();
            System.out.println(ping);
            jedis.flushDB();
            jedis.set("name", "lidy");
            System.out.println(jedis.exists("name"));
            System.out.println(jedis.get("name"));
        }
    }

}
